<?php

namespace App\Models\PartnerModels;

use App\Models\ParentModel;
use DB;
use App\Components\Tools;

/**
 * 轮播图model
 * @author puppet
 */
class Photo extends ParentModel
{
    /**
     * 与模型关联的数据表。
     *
     * @var string
     */
    protected $table = 'pt_admin_photo';

    /**
     * DB::直接操作的数据库表名
     * @var string
     */
    protected $db_table = 'pt_admin_photo';

    /**
     * 主键 默认id。
     *
     * @var string
     */
    protected $primaryKey = 'id';

    /**
     * 指定是否模型应该被戳记时间。
     *
     * @var bool
     */
    public $timestamps = false;

    //查询是否实名
    public function getRealName($params)
    {

        $sql = " select status,Business_license,sfz_zm_url,sfz_fm_url,create_time,update_time from pt_real_name  where  pid=$params";
        $sql .= " group by id order by update_time desc ";
        $res = DB::select($sql);
        //print_r($res);exit();
        if (empty($res)) {//没查到数据
            $res[0]['zt'] = '暂未实名';
            $res[0]['Business_license'] = '没有上传图片';
            $res[0]['sfz_zm_url'] = '没有上传图片';
            $res[0]['sfz_fm_url'] = '没有上传图片';
        } elseif ($res[0]['status'] == -1) {
            $res[0]['zt'] = '审核不通过';
        } elseif ($res[0]['status'] == 1) {
            $res[0]['zt'] = '审核中';
        } elseif ($res[0]['status'] == 2) {
            $res[0]['zt'] = '审核成功';
        }

        return $res;
    }

    //会员的雷达监控数据
    //合伙人对应的用户雷达数据获取 单次拉取20个数据 $size
    public function getLeiDaDate($id,$leixin,$day,$page){
        $time = date('Y-m-d ', time());
        $start_daytime = $time . ' 00:00:00';
        $end_time = $time . ' 23:59:59';
        $week=date('Y-m-d ',strtotime('-1week'));//一周前
        $month=date('Y-m-d ',strtotime('-1month'));//一周前
        $start_weektime = $week . ' 00:00:00';
        $start_monthtime = $month . ' 00:00:00';
        $size=20;
        $offset = $size * ($page - 1);
        $countsql="select count(a.id or b.id) as count from pt_user_info as a left join pt_user_live as b on a.partner_id=b.partner_id";
        $countsql.=" where a.id=$id";
        $sql=" select a.*,b.id as bid,b.room_id,b.info_name as bname,b.info_type as btype,create_time,b.status,b.room_url from pt_user_info as a ";
        $sql.=" left join pt_user_live as b on a.partner_id=b.partner_id";
        $sql.=" where a.id=$id";

        //查询对应的类型筛选的数据
        if($leixin==1){//主页
            $sql.=" and a.info_type=1 ";
            $countsql.=" and a.info_type=1 ";
        }elseif ($leixin==2){//视频
            $sql.=" and a.info_type=2 ";
            $countsql.=" and a.info_type=2 ";
        }elseif ($leixin==3){//广告
            $sql.=" and a.info_type=3 ";
            $countsql.=" and a.info_type=3 ";
        }elseif ($leixin==4){//直播
            $sql.=" and b.info_type=1 ";
            $countsql.=" and b.info_type=1 ";
        }
        //查询对应的时间段的数据 between '$week' and '$time'
        if($day==1){//当日的数据
            $sql.=" and (a.info_date between '$start_daytime' and '$end_time' or b.update_time between '$start_daytime' and '$end_time')";
            $countsql.=" and (a.info_date between '$start_daytime' and '$end_time' or b.update_time between '$start_daytime' and '$end_time')";
        }elseif ($day==2){//7天内
            $sql.=" and (a.info_date between '$start_weektime' and '$end_time' or b.update_time between '$start_weektime' and '$end_time')";
            $countsql.=" and (a.info_date between '$start_weektime' and '$end_time' or b.update_time between '$start_weektime' and '$end_time')";
        }elseif ($day==3){//一个月内
            $sql.=" and (a.info_date between '$start_monthtime' and '$end_time' or b.update_time between '$start_monthtime' and '$end_time')";
            $countsql.=" and (a.info_date between '$start_monthtime' and '$end_time' or b.update_time between '$start_monthtime' and '$end_time')";
        }
        $sql.=" limit {$offset},{$size}";
        $count=DB::select($countsql);
        $count=isset($count[0]['count']) ? $count[0]['count'] : 0;
        $data=DB::select($sql);
        $re=isset($data) ? $data : false;
        $html="";
        $nextPage=$page < ceil($count/$size) ? $page+1 : 0;
        //      print_r($re);exit();
        if($re){
            foreach($re as $k=>$v){
                $num_fls=$num_sop=$num_fans="";
                //获赞数
                if($v['info_support']>=10000){
                    $num_sop="<span style='color:red;font-size:18px;'>".round($v['info_support']/10000,1)." W</span> 赞";
                }else{
                    $num_sop="<span style='color:red;font-size:15px;'>".$v['info_support']."</span> 赞";
                }
                //评论数
                if($v['info_opus']>=10000){
                    $num_fls="<span style='color:red;font-size:18px;'>".round($v['info_opus']/10000,1)." W</span> 评论";
                }else{
                    $num_fls="<span style='color:red;font-size:18px;'>".$v['info_opus']." </span> 评论";
                }
                //分享数
                if($v['info_fans']>=10000){
                    $num_fans="<span style='color:red;font-size:18px;'>".round($v['info_fans']/10000,1)." W</span> 次分享";
                }else{
                    $num_fans="<span style='color:red;font-size:15px;'>".$v['info_fans']."</span> 次分享";
                }
                //判断是类型是什么
                $html.="<tr>";
                if(!empty($v['bin'])){//直播
                    $html.="<td>直播雷达</td>";
                    $html.="<td><a href=\"{$v['room_url']};\" target=\"_blank\" style=\"color:#00b7ee;\">".mb_substr($v['room_url'],0,10)."...".mb_substr($v['room_url'],-10)."</a></td>";
                    $html.="<td>{$v['room_id']}</td>";
                    $html.="<td>{$v['bname']}</td>";
                    $html.="<td>直播间链接</td>";
                    $html.="<td>无数据</td>";
                    $html.="<td>无数据</td>";
                    $html.="<td>无数据</td>";
                    $html.="<td>无数据</td>";
                    $html.="<td>无数据</td>";
                    $html.="<td>{$v['create_time']}</td>";
                    $html.="<td>潜在客户人数</td>";
                }else{
                    if(($v['info_type'])==1){//主页
                        $html.="<td>账户雷达</td>";
                        $html.="<td><a href='{$v['info_vurl']}' target='_blank'><img src='{$v['info_img']}' width='70' height='70'></a></td>";
                        $html.="<td>{$v['info_id']}</td>";
                        $html.="<td>{$v['info_name']}</td>";
                        $html.="<td>{$v['info_signature']}</td>";
                        $html.="<td><span style='color:red;font-size:18px;'>".$v['info_follow']."</span> 关注<br/><br/><span style='color:red;font-size:18px;'>".($v['info_fans']>=10000 ? round($v['info_fans']/10000,1)." W" : $v['info_fans'])."</span> 粉丝</td>";
                        $html.="<td><span style='color:red;font-size:18px;'>".$v['info_opus']."</span> 作品<br/><br/><span style='color:red;font-size:18px;'>".($v['info_support']>=10000 ? round($v['info_support']/10000,1)." W" : $v['info_support'])."</span> 赞</td>";
                        $Ccount=DB::select("select count(id) as count from pt_user_info_comment where type=? and partner_id={$id} and pt_type=1",[$v['id']]);
                        $Ccount=isset($Ccount[0]['count']) ? $Ccount[0]['count'] : 0;
                        $staTime=date('Y-m-d',strtotime(date('Y-m-d',time()-24*3600)))." 22:30:00";
                        $Ncount=DB::select("select count(id) as count from pt_user_info_comment where type=? and partner_id={$id} and pt_type=1 and update_time>='{$staTime}'",[$v['id']]);
                        $Ncount=isset($Ncount[0]['count']) ? $Ncount[0]['count'] : 0;
                        $html.="<td>无数据</td>";
                        $html.="<td>无数据</td>";
                        $html.="<td>无数据</td>";
                        $html.="<td>{$v['info_date']}</td>";
                        $html.="<td>{$Ccount} / {$Ncount}</td>";
                        //   print_r(1111);exit();
                    }elseif($v['info_type']==2){//视频
                        $html.="<td>视频雷达</td>";
                        $Ccount=DB::select("select count(id) as count from pt_user_info_comment where type=? and partner_id={$id} and pt_type=1 and video_id='{$v['number_id']}'",[0]);
                        $Ccount=isset($Ccount[0]['count']) ? $Ccount[0]['count'] : 0;
                        $html.="<td><a href='{$v['info_vurl']}' target='_blank'><img src='{$v['info_img']}' width='70' height='100'></a></td>";
                        $html.="<td>{$v['info_id']}</td>";
                        $html.="<td>{$v['info_name']}</td>";
                        $html.="<td>{$v['info_signature']}</td>";
                        $html.="<td>无数据</td>";
                        $html.="<td>无数据</td>";
                        $html.="<td>{$num_sop}</td>";
                        $html.="<td>{$num_fls}</td>";
                        $html.="<td>{$num_fans}</td>";
                        $html.="<td>{$v['info_date']}</td>";
                        $html.="<td>{$Ccount}</td>";
                    }elseif ($v['info_type']==3){//广告
                        $html.="<td>广告雷达</td>";
                        $Ccount=DB::select("select count(id) as count from pt_user_info_comment where type=? and partner_id={$id} and pt_type=1 and video_id='{$v['number_id']}'",[0]);
                        $Ccount=isset($Ccount[0]['count']) ? $Ccount[0]['count'] : 0;
                        $html.="<td><a href='{$v['info_vurl']}' target='_blank'><img src='{$v['info_img']}' width='70' height='100'></a></td>";
                        $html.="<td>{$v['info_id']}</td>";
                        $html.="<td>{$v['info_name']}</td>";
                        $html.="<td>{$v['info_signature']}</td>";
                        $html.="<td>无数据</td>";
                        $html.="<td>无数据</td>";
                        $html.="<td>{$num_sop}</td>";
                        $html.="<td>{$num_fls}</td>";
                        $html.="<td>{$num_fans}</td>";
                        $html.="<td>{$v['info_date']}</td>";
                        $html.="<td>{$Ccount}</td>";
                    }
                }
                $html.="</tr>";
            }
        }

        return ["html"=>$html,'nextPage'=>$nextPage];
    }


//查询咨询数据
    function getPageData($params)
    {
        $qiniuUrl = Tools::getOneconfig("/config/third.json", array('qiniu', 'qnUrl'));
        // echo "<pre>";print_r($params);exit();
        $size = (isset($params['limit']) && intval($params['limit']) > 0 && intval($params['limit']) <= 100) ? $params['limit'] : 5;
        $page = isset($params['page']) ? intval($params['page']) : 1;
        $offset = ($page - 1) * $size;

        $search_name = isset($params['search_user']) ? $params['search_user'] : '';
        $search_mobile = isset($params['search_mobile']) ? $params['search_mobile'] : '';
        $type = isset($params['search_type']) ? $params['search_type'] : '';
        $countSql = "select count(id) as count from $this->table  where status>=0";
        $sql = "SELECT id,content,photo_url,create_time,update_time,status,herf_url from $this->table where status>=0 ";


        if ($search_name) {
            $countSql .= " and user like '%{$search_name}%'";
            $sql .= " and user like '%{$search_name}%'";
        }
        if ($type) {
            $countSql .= " and type= $type ";
            $sql .= " and  type =$type ";
        }
        if ($search_name) {
            $countSql .= " and user like '%{$search_name}%'";
            $sql .= " and user like '%{$search_name}%'";
        }

        if ($search_mobile) {
            $countSql .= " and mobile like '%{$search_mobile}%'";
            $sql .= " and mobile like '%{$search_mobile}%'";
        }

        $sql .= " order by create_time desc limit $offset,$size";
        // echo $sql;exit;
        $count = DB::select($countSql);
        $count = isset($count[0]['count']) ? $count[0]['count'] : 0;
        $data = DB::select($sql);
        //print_r($data);
        if (!empty($data)) {
            $i = 0;
            foreach ($data as $k => $v) {
                $data[$k]['url'] = "<a href='{$qiniuUrl}/{$v['photo_url']}' target='_blank'><img src='{$qiniuUrl}/{$v['photo_url']}' style='width:80px;height:100px;'></a>";
                $data[$k]['comment'] = isset($v['comment']) ? $v['comment'] : '';

                $data[$k]['content'] = $v['content'];
                $data[$k]['create_time'] = $v['create_time'];
                if (!empty($v['herf_url'])) {
                    $data[$k]['herf_url'] = "<a href='{$v['herf_url']}' target='_blank'>点击前往跳转链接</a>";
                } else {
                    $data[$k]['herf_url'] = "未设置跳转链接";
                }
                $data[$k]['herf_url'] = "<a href='{$v['herf_url']}' target='_blank'>点击前往跳转链接</a>";
                if ($v['status'] == 1) {
                    $data[$k]['status'] = '<font color="#00bfff">开启</font>';
                } elseif ($v['status'] == 0) {
                    $data[$k]['status'] = '<font color="red">关闭</font>';
                } else {
                    $data[$k]['status'] = '未处理';
                }
                $data[$k]['update_time'] = $v['update_time'];
                $data[$k]['operation'] = '<button class="btn btn-info btn-sm" onclick="saveVoid(' . "'{$v['id']}','1'" . ')">开启</button>&nbsp;&nbsp;';
                $data[$k]['operation'] .= '<button class="btn btn-defult btn-sm" onclick="saveVoid(' . "'{$v['id']}','0'" . ')">关闭</button>&nbsp;&nbsp;';
                $data[$k]['operation'] .= '<button class="btn btn-danger btn-sm" onclick="saveVoid(' . "'{$v['id']}','-1'" . ')">删除</button>';
            }
        }
        return ['data' => $data, 'total' => $count];
    }

//修改状态
    function updateAll($kid, $data)
    {
        $sql = "update $this->table set ";
        if (is_array($data)) {
            foreach ($data as $k => $v) {
                $sql .= "`{$k}`='{$v}',";
            }
            $sql = substr($sql, 0, -1) . " where id={$kid}";
        }
        // echo $sql;exit;
        return DB::update($sql);
    }

//获取状态为开启的所有数据 首页轮播图数据 加上七牛配置
    function getAllInfo()
    {

        $sql = " select content,photo_url,status,herf_url from $this->table where status=1";
        $re = DB::select($sql);
        $url = Tools::getOneconfig("/config/third.json", array('qiniu', 'qnUrl'));
         foreach ($re as $k=>$v){
             $re[$k]['photo_url']=$url.'/'.$v['photo_url'];
         }
        return isset($re) ? $re : '';
    }

    //获取能用的tips
    function getTips()
    {
        $sql = " select content from pt_message where status=1 and type=3";
        $re = DB::select($sql);
        return isset($re) ? $re : '';
    }

    //获取询盘获客数据  需要传id过来
    function getxunpancount($id)
    {
        $time = date('Y-m-d ', time());
        $sql = " select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and create_time='$time' ";
        $re = DB::select($sql);
        return isset($re[0]['count']) ? $re[0]['count'] : '';
    }
    //数据中心接口 ---询盘数据
    function getKeywordCenter($id){
        $time = date('Y-m-d ', time());
        $day=date('Y-m-d H:i:s',strtotime('-1day'));//一天
        $week=date('Y-m-d ',strtotime('-1week'));//一周前
        $month=date('Y-m-d ',strtotime('-1month'));//一周前
        $sql = " select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and create_time='$time' ";
        $sxsql= " select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and create_time='$time' and status=1";
        $weeksql="select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and create_time between '$week' and '$time' ";
        $sxweeksql="select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and create_time between '$week' and '$time' and status=1";
        $monthsql="select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and create_time between '$week' and '$month' ";
        $sxmonthsql="select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and create_time between '$week' and '$month' and status=1";
        $allsql="select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id ";
        $sxallsql="select count(DISTINCT id) as count from pt_partner_comment where  partner_id=$id and status=1";
        $red= DB::select($sql);
        $redsx= DB::select($sxsql);
        $reweek=DB::select($weeksql);
        $reweeksx=DB::select($sxweeksql);
        $remonth=DB::select($monthsql);
        $remonthsx=DB::select($sxmonthsql);
        $all=DB::select($allsql);
        $allsx=DB::select($sxallsql);
        $data=array(
            'day'=>isset($red[0]['count']) ?$red[0]['count']:'',
            'daysx'=>isset($redsx[0]['count']) ?$redsx[0]['count']:'',
            'week'=>isset($reweek[0]['count']) ?$reweek[0]['count']:'',
            'weeksx'=>isset($reweeksx[0]['count']) ?$reweeksx[0]['count']:'',
            'month'=>isset($remonth[0]['count']) ?$remonth[0]['count']:'',
            'monthsx'=>isset($remonthsx[0]['count']) ?$remonthsx[0]['count']:'',
            'all'=>isset($all[0]['count']) ? $all[0]['count']:'',
            'allsx'=>isset($allsx[0]['count']) ? $allsx[0]['count']:'',
        );
        return $data;
    }

    //数据中心接口 ---获取视频数据/广告数据 type 2 视频数据 3广告数据
    function getVideoCenter($id,$type){
        $time = date('Y-m-d ', time());
        $start_daytime = $time . ' 00:00:00';
        $end_time = $time . ' 23:59:59';
        $week=date('Y-m-d ',strtotime('-1week'));//一周前
        $month=date('Y-m-d ',strtotime('-1month'));//一周前
        $start_weektime = $week . ' 00:00:00';
        $start_monthtime = $month . ' 00:00:00';
        $daysql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $daysql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_daytime' and '$end_time'";
        $daysxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $daysxsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_daytime' and '$end_time' and a.status=1 ";

        $weeksql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $weeksql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_weektime' and '$end_time'";
        $weeksxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $weeksxsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_weektime' and '$end_time' and a.status=1 ";

        $monthsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $monthsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_monthtime' and '$end_time'";
        $monthsxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $monthsxsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_monthtime' and '$end_time' and a.status=1";

        $allsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $allsql .= " where a.partner_id=$id and b.info_type=$type";
        $allsxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $allsxsql .= " where a.partner_id=$id and b.info_type=$type and a.status=1 ";
        $red= DB::select($daysql);
        $redsx= DB::select($daysxsql);
        $reweek=DB::select($weeksql);
        $reweeksx=DB::select($weeksxsql);
        $remonth=DB::select($monthsql);
        $remonthsx=DB::select($monthsxsql);
        $all=DB::select($allsql);
        $allsx=DB::select($allsxsql);
        $data=array(
            'day'=>isset($red[0]['count']) ?$red[0]['count']:'',
            'daysx'=>isset($redsx[0]['count']) ?$redsx[0]['count']:'',
            'week'=>isset($reweek[0]['count']) ?$reweek[0]['count']:'',
            'weeksx'=>isset($reweeksx[0]['count']) ?$reweeksx[0]['count']:'',
            'month'=>isset($remonth[0]['count']) ?$remonth[0]['count']:'',
            'monthsx'=>isset($remonthsx[0]['count']) ?$remonthsx[0]['count']:'',
            'all'=>isset($all[0]['count']) ? $all[0]['count']:'',
            'allsx'=>isset($allsx[0]['count']) ? $allsx[0]['count']:'',
        );
        return $data;
    }

    //数据中心接口 ---获取达人数据
    function getdrCenter($id,$type){
        $time = date('Y-m-d ', time());
        $start_daytime = $time . ' 00:00:00';
        $end_time = $time . ' 23:59:59';
        $week=date('Y-m-d ',strtotime('-1week'));//一周前
        $month=date('Y-m-d ',strtotime('-1month'));//一周前
        $start_weektime = $week . ' 00:00:00';
        $start_monthtime = $month . ' 00:00:00';
        $daysql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $daysql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_daytime' and '$end_time'";
        $daysxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $daysxsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_daytime' and '$end_time' and a.status=1 ";

        $weeksql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $weeksql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_weektime' and '$end_time'";
        $weeksxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $weeksxsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_weektime' and '$end_time' and a.status=1 ";

        $monthsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $monthsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_monthtime' and '$end_time'";
        $monthsxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $monthsxsql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_monthtime' and '$end_time' and a.status=1";

        $allsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $allsql .= " where a.partner_id=$id and b.info_type=$type";
        $allsxsql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";
        $allsxsql .= " where a.partner_id=$id and b.info_type=$type and a.status=1 ";
        $red= DB::select($daysql);
        $redsx= DB::select($daysxsql);
        $reweek=DB::select($weeksql);
        $reweeksx=DB::select($weeksxsql);
        $remonth=DB::select($monthsql);
        $remonthsx=DB::select($monthsxsql);
        $all=DB::select($allsql);
        $allsx=DB::select($allsxsql);
        $data=array(
            'day'=>isset($red[0]['count']) ?$red[0]['count']:'',
            'daysx'=>isset($redsx[0]['count']) ?$redsx[0]['count']:'',
            'week'=>isset($reweek[0]['count']) ?$reweek[0]['count']:'',
            'weeksx'=>isset($reweeksx[0]['count']) ?$reweeksx[0]['count']:'',
            'month'=>isset($remonth[0]['count']) ?$remonth[0]['count']:'',
            'monthsx'=>isset($remonthsx[0]['count']) ?$remonthsx[0]['count']:'',
            'all'=>isset($all[0]['count']) ? $all[0]['count']:'',
            'allsx'=>isset($allsx[0]['count']) ? $allsx[0]['count']:'',
        );
        return $data;
    }
    //获取关键词获客私信次数
    function getkeyWordCount($id)
    {
        $time = date('Y-m-d ', time());
        $sql = " select count(DISTINCT id) as count from pt_partner_comment where partner_id=$id and create_time='$time' and status=1 ";
        $re = DB::select($sql);
        return isset($re[0]['count']) ? $re[0]['count'] : '';
    }

//获取视频的获客数据 --通用方法确定雷达和广告的区别
    function getVideoCount($id, $type)
    {
        $time = date('Y-m-d ', time());
        $start_time = $time . ' 00:00:00';
        $end_time = $time . ' 23:59:59';
        $sql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $sql .= " where a.partner_id=$id and b.info_type=$type and a.update_time between '$start_time' and '$end_time'";
        $re = DB::select($sql);
        //   return $sql;
        return isset($re[0]['count']) ? $re[0]['count'] : '';
    }

    //获取视频获取数据的私信数据--通用方法确定雷达和广告的区别  1 雷达 2主页 3广告
    function getVideoSxCount($id, $type)
    {
        $time = date('Y-m-d ', time());
        $start_time = $time . ' 00:00:00';
        $end_time = $time . ' 23:59:59';
        $sql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id";
        $sql .= " where a.status=1 and  a.partner_id=$id and b.info_type=$type and a.update_time between '$start_time' and '$end_time'";
        $re = DB::select($sql);
        return isset($re[0]['count']) ? $re[0]['count'] : '';
    }

    //获取达人（主页雷达）获客数据
    function getDrCount($id, $type)
    {
        $time = date('Y-m-d ', time());
        $start_time = $time . ' 00:00:00';
        $end_time = $time . ' 23:59:59';
        $sql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";//查询账号数据
        $sql .= " where  a.partner_id=$id and b.info_type=$type and a.update_time between '$start_time' and '$end_time'";
        $re = DB::select($sql);
        return isset($re[0]['count']) ? $re[0]['count'] : '';
    }

    //获取达人（主页雷达）私信数量
    function getDrSxCount($id, $type)
    {
        $time = date('Y-m-d ', time());
        $start_time = $time . ' 00:00:00';
        $end_time = $time . ' 23:59:59';
        $sql = "select count(DISTINCT a.id) as count from pt_user_info_comment as a left join pt_user_info as b on a.partner_id=b.partner_id and a.type=b.id";//查询账号数据
        $sql .= " where a.status=1 and a.partner_id=$id and b.info_type=$type and a.update_time between '$start_time' and '$end_time'";
        $re = DB::select($sql);
        return isset($re[0]['count']) ? $re[0]['count'] : '';
    }
}